home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 108 / MacAddict108.iso / Software / Internet & Communication / WordPress 1.5.1.dmg / wordpress / wp-admin / templates.php < prev    next >
Encoding:
PHP Script  |  2005-05-09  |  4.4 KB  |  154 lines

  1. <?php
  2. require_once('admin.php');
  3. $title = __('Template & File Editing');
  4. $parent_file =     'edit.php';
  5.  
  6. $wpvarstoreset = array('action','redirect','profile','error','warning','a','file');
  7. for ($i=0; $i<count($wpvarstoreset); $i += 1) {
  8.     $wpvar = $wpvarstoreset[$i];
  9.     if (!isset($$wpvar)) {
  10.         if (empty($_POST["$wpvar"])) {
  11.             if (empty($_GET["$wpvar"])) {
  12.                 $$wpvar = '';
  13.             } else {
  14.                 $$wpvar = $_GET["$wpvar"];
  15.             }
  16.         } else {
  17.             $$wpvar = $_POST["$wpvar"];
  18.         }
  19.     }
  20. }
  21.  
  22. $recents = get_option('recently_edited');
  23.  
  24. if (empty($file)) {
  25.     if ($recents) {
  26.         $file = $recents[0];
  27.     } else {
  28.         $file = 'index.php';
  29.     }
  30. }
  31.  
  32. $file = validate_file_to_edit($file);
  33. $real_file = get_real_file_to_edit($file);
  34.  
  35. switch($action) {
  36.  
  37. case 'update':
  38.  
  39.     if ($user_level < 5) {
  40.         die(__('<p>You have do not have sufficient permissions to edit templates for this blog.</p>'));
  41.     }
  42.  
  43.     $newcontent = stripslashes($_POST['newcontent']);
  44.     if (is_writeable($real_file)) {
  45.         $f = fopen($real_file, 'w+');
  46.         fwrite($f, $newcontent);
  47.         fclose($f);
  48.         header("Location: templates.php?file=$file&a=te");
  49.     } else {
  50.         header("Location: templates.php?file=$file");
  51.     }
  52.  
  53.     exit();
  54.  
  55. break;
  56.  
  57. default:
  58.  
  59.     require_once('./admin-header.php');
  60.     if ( $user_level <= 5 )
  61.         die(__('<p>You have do not have sufficient permissions to edit templates for this blog.</p>'));
  62.  
  63.     if ( strstr( $file, 'wp-config.php' ) )
  64.         die( __('<p>The config file cannot be edited or viewed through the web interface. Sorry!</p>') );
  65.  
  66.     update_recently_edited($file);
  67.  
  68.     if (!is_file($real_file))
  69.         $error = 1;
  70.     
  71.     if (!$error) {
  72.         $f = fopen($real_file, 'r');
  73.         $content = fread($f, filesize($real_file));
  74.         $content = htmlspecialchars($content);
  75.     }
  76.  
  77.     ?>
  78. <?php if (isset($_GET['a'])) : ?>
  79.  <div class="updated"><p><?php _e('File edited successfully.') ?></p></div>
  80. <?php endif; ?>
  81.  <div class="wrap"> 
  82. <?php
  83. if (is_writeable($real_file)) {
  84.     echo '<h2>' . sprintf(__('Editing <strong>%s</strong>'), wp_specialchars($file) ) . '</h2>';
  85. } else {
  86.     echo '<h2>' . sprintf(__('Browsing <strong>%s</strong>'), wp_specialchars($file) ) . '</h2>';
  87. }
  88. ?>
  89. <div id="templateside">
  90. <?php 
  91. if ( $recents ) : 
  92. ?>
  93. <h3><?php _e('Recent'); ?></h3>
  94. <?php
  95. echo '<ol>';
  96. foreach ($recents as $recent) :
  97.     echo "<li><a href='templates.php?file=$recent'>" . get_file_description(basename($recent)) . "</a></li>";
  98. endforeach;
  99. echo '</ol>';
  100. endif;
  101. ?>
  102. <h3><?php _e('Common'); ?></h3>
  103.     <?php $common_files = array('index.php', '.htaccess', 'my-hacks.php');
  104.  $old_files = array('wp-layout.css', 'wp-comments.php', 'wp-comments-popup.php');
  105.  foreach ($old_files as $old_file) {
  106.      if (file_exists(ABSPATH . $old_file))
  107.          $common_files[] = $old_file;
  108.  } ?>
  109.   <ul>
  110.      <?php foreach ($common_files as $common_file) : ?>
  111.       <li><a href="templates.php?file=<?php echo $common_file?>"><?php echo get_file_description($common_file); ?></a></li>
  112.      <?php endforeach; ?>
  113.   </ul>
  114. </div>
  115. <?php if (!$error) { ?>
  116.   <form name="template" id="template" action="templates.php" method="post"> 
  117.      <div><textarea cols="70" rows="25" name="newcontent" id='newcontent' tabindex="1"><?php echo $content ?></textarea> 
  118.      <input type="hidden" name="action" value="update" /> 
  119.      <input type="hidden" name="file" value="<?php echo $file ?>" /> 
  120. </div>
  121. <?php if ( is_writeable($real_file) ) : ?>
  122.      <p class="submit">
  123. <?php
  124.     echo "<input type='submit' name='submit' value='    " . __('Update File') . " »' tabindex='2' />";
  125. ?>
  126. </p>
  127. <?php else : ?>
  128. <p><em><?php _e('If this file was writable you could edit it.'); ?></em></p>
  129. <?php endif; ?>
  130.    </form> 
  131.   <?php
  132.     } else {
  133.         echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
  134.     }
  135.     ?>
  136. </div>
  137. <div class="wrap">
  138. <h2><?php _e('Other Files') ?></h2>
  139.  
  140.   <p><?php _e('To edit a file, type its name here. You can edit any file <a href="http://codex.wordpress.org/Changing_File_Permissions" title="Read more about making files writable">writable by the server</a>, e.g. CHMOD 666.') ?></p> 
  141.   <form name="file" action="templates.php" method="get"> 
  142.     <input type="text" name="file" /> 
  143.     <input type="submit" name="submit"  value="<?php _e('Edit file »') ?>" /> 
  144.   </form> 
  145.  
  146.   <p><?php _e('Note: of course, you can also edit the files/templates in your text editor of choice and upload them. This online editor is only meant to be used when you don’t have access to a text editor or FTP client.') ?></p>
  147. </div> 
  148. <?php
  149.  
  150. break;
  151. }
  152.  
  153. include("admin-footer.php");
  154. ?>